$(document).ready(function() {
	$("form").submit(function() {
		$("input[name='username']+span,input[name='userpassword']+span,select[name='role']+span").css("display","none");
		$.post("AddUser.do", $("form").serialize(), function(result) {
			result = eval('(' + result + ")");
			if(result.status != undefined){
				if(result.status == 'ok'){
					window.location.href="ListUser.do";
					return;
				}else if(result.status == 'error' && result.msg != undefined){
					alert(result.msg)
				}
			}
			if(result.username != undefined){
				$("input[name='username']+span").css("display","inline-block");
				$("input[name='username']+span").html("<i class=\"icon iconfont\">&#xe624;</i>" + result.username +"");
			}
			if(result.userpassword != undefined){
				$("input[name='userpassword']+span").css("display","inline-block");
				$("input[name='userpassword']+span").html("<i class=\"icon iconfont\">&#xe624;</i>" + result.userpassword +"");
			}
			if(result.role != undefined){
				$("select[name='role']+span").css("display","inline-block");
				$("select[name='role']+span").html("<i class=\"icon iconfont\">&#xe624;</i>" + result.role +"");
			}
		});
		return false;
	});
})